package com.demo.woziqi;

import com.demo.woziqi.dao.ResultDao;
import com.demo.woziqi.entity.User;
import com.demo.woziqi.util.GameConstant;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.util.List;

/**
 * @Author 宋明松
 * @Version V1.0.0
 * @Date 2022-05-23
 * <p>
 * 用户对战记录日志查看窗口
 */
public class GameUserHistoryStage extends Stage {
    private ScrollPane sp = new ScrollPane();
    private VBox vb = new VBox();
    private Label fileName = new Label();

    public GameUserHistoryStage() {
        VBox box = new VBox();
        Scene scene = new Scene(box, 380, 500);
        this.setScene(scene);
        this.setTitle("历史对战记录");
        box.getChildren().addAll(sp, fileName);
        VBox.setVgrow(sp, Priority.ALWAYS);
        fileName.setLayoutX(30);
        fileName.setLayoutY(160);
        ResultDao resultDao = new ResultDao();
        User user = new User();
        user.setId(GameConstant.user.getId());
        List<String> listBlack = resultDao.getResultBlack(user); //  我方棋子黑色的对战记录
        List<String> listWhite = resultDao.getResultWhite(user); //  我方棋子白色的对战记录
        Label resName = new Label("----------我方为黑棋对战结果----------");
        vb.getChildren().add(resName);
        if (listBlack.size() == 0) {  // 没有数据时，显示无记录
            Label name = new Label("无记录");
            vb.getChildren().add(name);

        } else {
            for (int i = 0; i < listBlack.size(); i++) { // 有数据，遍历出来并显示
                Label name = new Label(listBlack.get(i));
                vb.getChildren().add(name);
            }
        }
        Label resName2 = new Label("----------我方为白棋对战结果----------");
        vb.getChildren().add(resName2);
        if (listWhite.size() == 0) {// 没有数据时，显示无记录
            Label name = new Label("无记录");
            vb.getChildren().add(name);
        } else {
            for (int i = 0; i < listWhite.size(); i++) {// 有数据，遍历出来并显示
                Label name = new Label(listWhite.get(i));
                vb.getChildren().add(name);
            }
        }
        sp.setVmax(440);
        sp.setPrefSize(115, 150);
        sp.setContent(vb);
        sp.vvalueProperty().addListener((ObservableValue<? extends Number> ov,
                                         Number old_val, Number new_val) -> {
            fileName.setText("                          历史对战记录日志查看器");
        });
    }
}
